function btnadd() {
    window.location.href = "/student/createoredit"
}

function btnback() {
    window.location.href = "/student/index"
}

function btnedit(id) {
    window.location.href = `/student/createoredit/${id}`
}

function btndel(id) {
    if (confirm("确定删除？")) {
        window.location.href = `/student/delete/${id}`
    }
}

function btnsave(id) {
    var name = $("[name=name]").val();
    var age = $("[name=age]").val();
    var id = $("[name=id]").val();
    var gradeClassId = $("[name=classid]").val();
    var obj = {
        id,
        name,
        gradeClassId,
        age
    }
    $.post("/student/save", obj, function() {
        alert("保存成功");
        window.location.href = "/student/index";
    })
}

function btnquery() {
    var word = $("[name=keyword]").val();
    var obj = {
        word
    }
    $.post("/student/query", obj, function(res) {
        $("[name=tbdata]").html("");
        res.forEach(item => {
            var html = `
                 <tr>
                    <td>${item.id}</td>
                    <td>${item.name}</td>
                    <td>${item.age}</td>
                    <td>
                        <button onclick="btnedit(${item.id})">修改</button>
                        <button onclick="btndel(${item.id})">删除</button>
                    </td>
                </tr>
                <tr><td><button onclick="btnback()">返回</button></td><tr>
            `
            $("[name=tbdata]").append(html);
        });
    })
}